<%@ page language="java" pageEncoding="utf8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" href="<c:url value="/css/shopadmin.css"/>" type="text/css" />
		<link rel="stylesheet" href="<c:url value='/scripts/themes/base/jquery.ui.all.css'/>" type="text/css" />

	</head>
	<body>
		<div id="headBar" class="head_content">
			<div class="finder-action" id="">
				<div class="finder-action-inner clearfix">
					<button type="button" onclick="location.href = 'mt_coupon_add.html'" class="btn btn-xl-large">
						<span><span><i class="finder-icon"><img src="<c:url value="/images/transparent.gif"/>" class="imgbundle icon"
										style="width: 24px; height: 24px; background-position: 0pt -316px;">
							</i>添加优惠券</span> </span>
					</button>
					<button type="button" onclick="location.reload();" class="btn">
						<span><span><i class="finder-icon"><img src="<c:url value="/images/transparent.gif"/> " class="imgbundle icon"
										style="width: 22px; height: 24px; background-position: 0pt -644px;">
							</i>刷新</span> </span>
					</button>
					<button type="button" onclick="couponBatchDelete();" class="btn">
						<span><span><i class="finder-icon"><img src="<c:url value="/images/transparent.gif"/> " class="imgbundle icon"
										style="width: 17px; height: 24px; background-position: 0pt -757px;">
							</i>删除</span> </span>
					</button>
				</div>
			</div>
			<div class="finder-header">

				<table width="100%" cellspacing="0" cellpadding="0">
					<!----cols---->
					<col class="span-select" style="width: 24px;" />
					<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 70px;" />
						<col style="width: 70px;" />
						<col style="width: 70px;" />
					<col />
					<!----cols---->
					<thead>
						<tr>
							<td>
								<input type="checkbox" id="cpns_ids" class="sellist">
							</td>
							<td>
								<table width="100%" cellspacing="0" cellpadding="0">
									<tbody>
										<tr>
											<td>
												<span class="finder-col-label">操作</span>
											</td>
										</tr>
									</tbody>
								</table>
							</td>
							<td>
								<div key="cpns_name" class="cell orderable">
									<table width="100%" cellspacing="0" cellpadding="0">
										<tbody>
											<tr>
												<td>
													<span class="finder-col-label">优惠券名称</span>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</td>
							<td>
								<div key="cpns_prefix" class="cell orderable">
									<table width="100%" cellspacing="0" cellpadding="0">
										<tbody>
											<tr>
												<td>
													<span class="finder-col-label">优惠券前缀</span>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</td>
							<td>
								<div key="pmt_time_begin" class="cell orderable">
									<table width="100%" cellspacing="0" cellpadding="0">
										<tbody>
											<tr>
												<td>
													<span class="finder-col-label">开始时间</span>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</td>
							<td>
								<div key="pmt_time_end" class="cell orderable">
									<table width="100%" cellspacing="0" cellpadding="0">
										<tbody>
											<tr>
												<td>
													<span class="finder-col-label">结束时间</span>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</td>
							<td>
								<div key="cpns_type" class="cell orderable">
									<table width="100%" cellspacing="0" cellpadding="0">
										<tbody>
											<tr>
												<td>
													<span class="finder-col-label">优惠券类型</span>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</td>
							<td>
								<div key="cpns_status" class="cell orderable">
									<table width="100%" cellspacing="0" cellpadding="0">
										<tbody>
											<tr>
												<td>
													<span class="finder-col-label">是否启用</span>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</td>
							<td>
								<div key="cpns_gen_quantity" class="cell orderable">
									<table width="100%" cellspacing="0" cellpadding="0">
										<tbody>
											<tr>
												<td>
													<span class="finder-col-label">总数量</span>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</td>
							<td>
								<div key="cpns_point" class="cell orderable">
									<table width="100%" cellspacing="0" cellpadding="0">
										<tbody>
											<tr>
												<td>
													<span class="finder-col-label">兑换所需积分</span>
												</td>

											</tr>
										</tbody>
									</table>
								</div>
							</td>
							<td>
								&nbsp;
							</td>
						</tr>
					</thead>
				</table>
			</div>
		</div>
		<div id="main" class="main_content">
			<div class="finder-list finder-list-normal">
				<form id="list_form" action="mt_coupon_delete.html" method="post">
					<table cellpadding="0" cellspacing="0" width="100%" id="coupon_tbl">
						<!----cols---->
						<col class="span-select" style="width: 24px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 140px;" />
						<col style="width: 70px;" />
						<col style="width: 70px;" />
						<col style="width: 70px;" />
						<col />
						<!----cols---->
						<tbody>
							<c:forEach var="coupon" items="${marketCouponss}" varStatus="index">
								<tr class="row">
									<td>
										<input onclick="changeColor(this);" type="checkbox" value="${coupon.couponId}" name="marketCouponss[${index.index}]" class="sel" />
									</td>

									<td key="_cmd">
										<div class="cell">
											<a href="mt_coupon_edit.html?couponId=${coupon.couponId}"><img style="width: 15px; height: 16px; background-position: 0pt -133px;" class="imgbundle"
													src="<c:url value="/images/transparent.gif"/>">
													编辑 
											</a> &nbsp;&nbsp;
											<span onclick="generateMCDialog(${coupon.couponId})" class="lnk"><img style="width: 15px; height: 16px; background-position: 0pt -117px;" class="imgbundle" src="<c:url value="/images/transparent.gif"/>">
													下载 
											</span>
										</div>
									</td>
									<td key="cpns_name">
										<div class="cell">
											${coupon.couponName}
										</div>
									</td>
									<td key="cpns_prefix">
										<div class="cell">
											${coupon.couponPrefix}
										</div>
									</td>
									<td key="pmt_time_begin">
										<div class="cell">
											${coupon.pmtTimeBeginString }
										</div>
									</td>
									<td key="pmt_time_end">
										<div class="cell">
											${coupon.pmtTimeEndString }
										</div>
									</td>
									<td  >
										<div class="cell">
											 ${coupon.pmtMethod }
										</div>
									</td>
									<td key="cpns_status">
										<div class="cell">
											${coupon.couponStatus}
										</div>
									</td>
									<td key="cpns_gen_quantity">
										<div class="cell" id="cq_${coupon.couponId}">
											${coupon.couponQuantity}
										</div>
									</td>
									<td key="cpns_point">
										<div class="cell">
											${coupon.couponPoint}
										</div>
									</td>
									<td>
										&nbsp;
									</td>
								</tr>

							</c:forEach>

						</tbody>
					</table>
				</form>

			</div>

		</div>
		<div id="footBar" class="foot_content">
			<div class="finder-footer" id="finder-footer-ea2899">
				<div class="finder-page clearfix">
					<div class="span-3">

					</div>
					<div class="span-auto">
						${pagerString }
					</div>
					<div class="span-auto textright">
						共
						<i>${fn:length(marketCouponss)}</i>条
					</div>
				</div>
			</div>

		</div>

		<div id="member_coupon_dialog" title="批量生成优惠券" style="display: none;">
			
			<div  >
				<div class="division">
					<div class="notice">

						警告：如果生成超过10万的优惠券,请在选择系统负载较轻的时间,如凌晨。
						<br />
						为所有会员生成优惠券时,只能使用在线的发行方式。
						<br /> 
					</div>
					<form id="mcbi_form" action="mt_coupon_batch_insert.html" method="post">
					<input type="hidden" id="mc_couponId"  name="couponId" /> 
					<table cellspacing="0" cellpadding="0" border="0">						
						<tr>
							<th style="width: 20px;">
								&nbsp;&nbsp;&nbsp;&nbsp;
							</th>
							<th>
								<label for="bated_ipt_uniformStore">
									发行方式
								</label>
							</th>
							<td>								 
								<select id="mc_type" name="mcOnline" onchange="changeMCType(this)">
									<option value="true" >在线</option>
									<option value="false" >离线</option>
								</select>
							</td>
						</tr>
						<tr id="ct_tr">
							<th style="width: 20px;">
								&nbsp;&nbsp;&nbsp;&nbsp;
							</th>
							<th>
								<label >
									生成数量
								</label>
							</th>
							<td>		
								<input id="allUserFlag_false"  name="allUserFlag" value="false" type="radio" checked="checked"  onclick="$('#mc_count_tr').css('display','');"  />指定数量						 
								<input  name="allUserFlag" value="true" type="radio" onclick="$('#mc_count_tr').css('display','none');" />全部会员
								
							</td>
						</tr>
						<tr id="mc_count_tr">
							<th style="width: 20px;">
								&nbsp;&nbsp;&nbsp;&nbsp;
							</th>
							<th>
								<label for="">
									数量
								</label>

							</th>
							<td>
								<input class="x-input" id="mc_count" name="count"   type="text" />
							</td>
						</tr>
						


					</table>
</form>



				</div>

				<div class="mainFoot">
					<table cellspacing="0" cellpadding="0" border="0" align="center" class="table-action">
						<tbody>
							<tr>
								<td>
									<button class="sysiconBtnNoIcon" onclick="batchGenSubmit(this)" >
										批量生成
									</button>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>

		<script type="text/javascript" src="<c:url value='/scripts/jquery-1.4.2.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.core.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.widget.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.mouse.js'/> "></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.button.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.draggable.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.position.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.dialog.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.effects.core.js'/> "></script>

		<%@ include file="/jsp/admin/common/messages.jsp"%>


		<script type="text/javascript">
		
		
		
	var selected = 'selected';
	$("#cpns_ids").click(function() {

		if (this.checked) {
			$('input[type=checkbox]').attr("checked", true);

			$('#coupon_tbl >tbody> tr').addClass(selected);
		} else {
			$('input[type=checkbox]').attr("checked", false);
			$('#coupon_tbl > tbody > tr').removeClass(selected);
		}
	});

	function changeColor(obj) {
		if ($(obj).attr("checked")) {
			$(obj).parent().parent().addClass(selected);
		} else {
			$(obj).parent().parent().removeClass(selected);
		}
	}

	function couponBatchDelete() {
		var selected = false;
		$('#coupon_tbl input[type=checkbox]').each(function(i, dom) {
			if ($(dom).attr("checked")) {
				selected = true;
			}
		});
		if (!selected) {
			alert('请选择要删除的优惠券');
			return;
		}
		if (!confirm("确定删除吗？")) {
			return;
		}
		$('#list_form').submit();
	}
	
	
	
	$(function() {	
			
        	$("#member_coupon_dialog").dialog({
				autoOpen: false,
				height: 350,
				width: 550,
				modal: true,
				close: function() {
					 
				}
			});
        });
        function generateMCDialog(couponId){	
        	$('#mc_couponId').val(couponId);	 	
			$('#member_coupon_dialog').dialog('open');
		}
	
	
	
	function batchGenSubmit(obj){
		
		
		if($(obj).attr("disabled")){
			alert('已经提交,请等待操作完成');
		}
		
		if(!confirm('确定操作吗?')){
				return;
		}
		
		var mc_couponId = $('#mc_couponId').val();
		var count = $('#mc_count').val();
		var mcOnline = $('#mc_type').val();
		
		$(obj).attr("disabled",true);
		if(mcOnline){
			$('#mcbi_form').submit();
		}		
		if(mc_couponId!=0){
			var url = "mt_coupon_batch_insert.html";
			var params = {
				"couponId" : mc_couponId ,
				"count" : count ,
				"mcOnline" :mcOnline
			};	
			$.getJSON(url, params, 
				function callback(data) 
				{			
					$('#member_coupon_dialog').dialog('close');					
					$('#cq_'+mc_couponId).html('');
					$('#cq_'+mc_couponId).html(data.newQuantity);				
					var  returnString = "成功";	
					showCallbackResult(returnString);						
				}
			);			
		} 
		
		$(obj).attr("disabled",false);
	}
	
	function changeMCType(obj){
		var value = $(obj).val();
		
		if(value =='true'){
			$('#ct_tr').css('display','');
			if($('#allUserFlag_false').attr("checked")){
				$('#mc_count_tr').css('display','');
			}else{
				$('#mc_count_tr').css('display','none');
			}
		}else{
			$('#ct_tr').css('display','none');
			$('#mc_count_tr').css('display','');
		}
		
		
	}
	 
</script>


	</body>


</html>









